using UnityEngine;

public class WrapAround : MonoBehaviour
{
    public float wrapPointX = 15f;
    public float wrapPointZ = 12f;

    void Update()
    {
        // Check if the position exceeds the wrap point on the x-axis
        if (transform.position.x > wrapPointX)
        {
            // Teleport to the opposite side on the x-axis
            transform.position = new Vector3(-wrapPointX, transform.position.y, transform.position.z);
        }
        else if (transform.position.x < -wrapPointX)
        {
            // Teleport to the opposite side on the x-axis
            transform.position = new Vector3(wrapPointX, transform.position.y, transform.position.z);
        }

        // Check if the position exceeds the wrap point on the z-axis
        if (transform.position.z > wrapPointZ)
        {
            // Teleport to the opposite side on the z-axis
            transform.position = new Vector3(transform.position.x, transform.position.y, -wrapPointZ);
        }
        else if (transform.position.z < -wrapPointZ)
        {
            // Teleport to the opposite side on the z-axis
            transform.position = new Vector3(transform.position.x, transform.position.y, wrapPointZ);
        }
    }
}